import React, { PureComponent } from 'react';
import {
  Row,
  Col,
  Card,
  Form,
  Button,
  Input,
  DatePicker,
  Table,
  Select,
  Icon,
  Divider,
  Popconfirm,
  Modal,
  message,
  Alert,
  Steps,
} from 'antd';
import moment from 'moment';
import { connect } from 'dva';
import router from 'umi/router';
const FormItem = Form.Item;
const Option = Select.Option;
const currentYear = new Date().getFullYear();
const years = [
  { nodeName: currentYear, key: currentYear },
  { nodeName: currentYear - 1, key: currentYear - 1 },
  { nodeName: currentYear - 2, key: currentYear - 2 },
  { nodeName: currentYear - 3, key: currentYear - 3 },
];
const months = [
  { nodeName: 1, key: 1 },
  { nodeName: 2, key: 2 },
  { nodeName: 3, key: 3 },
  { nodeName: 4, key: 4 },
  { nodeName: 5, key: 5 },
  { nodeName: 6, key: 6 },
  { nodeName: 7, key: 7 },
  { nodeName: 8, key: 8 },
  { nodeName: 9, key: 9 },
  { nodeName: 10, key: 10 },
  { nodeName: 11, key: 11 },
  { nodeName: 12, key: 12 },
];
@Form.create()
@connect()
class ProjectContactApprove extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
    };
    this.dispatch = this.props.dispatch;
  }
  submitAddValues = values => {
    const hide = message.loading('正在修改...', 0);
    values.id=this.props.record.id;
    this.props.dispatch({
      type: 'ProjectContact/fetchProjectContactAuditEdit',
      payload: {
        cm: values,
      },
      callback: response => {
        hide();
        if (response.status) {
          message.success('修改成功');
          this.setState({ visible: false });
          this.props.fetchList();
        } else {
          message.error(response.ErrorMessage);
          console.log(response.ErrorMessage);
        }
      },
    });
  };
  submmitFormValues = () => {
    this.props.form.validateFields((err, values) => {
      if (!err) {
        this.submitAddValues(values);
      }
    });
  };
  componentDidMount() {
    // debugger
    this.props.OnRef({ ref: this, type: 'ApproveForm' });
  }
  render() {
    const { getFieldDecorator } = this.props.form;
    const { companyList } = this.props;
    const formItemLayout = {
      labelCol: {
        xs: { span: 3 },
        sm: { span: 3 },
      },
      wrapperCol: {
        xs: { span: 21 },
        sm: { span: 21 },
      },
    };
    const width = '500px';
    return (
      <>
        <Modal
          title="审批"
          width={'70%'}
          destroyOnClose
          visible={this.state.visible}
          onOk={() => {
            this.submmitFormValues();
          }}
          onCancel={() => {
            this.setState({ visible: false });
          }}
        >
          <Card style={{ margin: '5px 0' }}>
            <Form   {...formItemLayout}>
              <FormItem label="审批内容">
                {getFieldDecorator('spnr', {
                  initialValue: this.props.record&&this.props.record.spnr&&this.props.record.spnr,
                  rules: [
                    {
                      required: true,
                      message: '审批内容',
                    },
                  ],
                })(<Input.TextArea row={8} placeholder={'审批内容'} />)}
              </FormItem>
            </Form>
          </Card>
        </Modal>
      </>
    );
  }
}

export default ProjectContactApprove;
